<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript">

$(function () {
    var fields = new Array('alienationType','alienationComment');
        disableFields(fields);
});

$(document).ready(function () {
    loadAlienationData();
});

function loadAlienationData() {
    $('#alienationMethod').val($('#alienationType').val());

    if ($('#alienationType').val() == 0) {
        $("#alienation-details").hide();
        $("#commentOnAlienation").hide();
        $("#alienationDocuments").hide();

    } else {

        $("#alienation-details").show();
        var landId = '<s:property value="landId"/>';
        var url = '${"loadInitAlienationPagePrintReport.do?landId=' + landId + '"}';
        $.post(url, $('#load-form').serialize(), function (data) {
            $("#alienation-details").html(data);
            if ($('#alienationType').val() == unalienated) {
                $("#commentOnAlienation").hide();
                $("#alienationDocuments").hide();

            } else {
                $("#commentOnAlienation").show();
                $("#alienationDocuments").show();

            }
            $('#tabs').tabs();
        });
    }
}

//todo: move to landalienationinformation.js
/*function validateFields() {

    if ($('#alienationType').val() == 0) {
        $("#alienationType").rules("add", {selectBox:"default", messages:{
            selectBox:$('#pls_select_alienation_method').val()}
        });
    }

    if ($('#alienationType').val() != unalienated) {

        $("#referenceNo").rules("add", {required:true, messages:{
            required:$('#this_field_required').val()}
        });

        $("#verifiedByBeneficiarytrue").rules("add", {required:true, messages:{
            required:$('#this_field_required').val()}
        });
        $("#verifiedByBeneficiaryfalse").rules("add", {required:true, messages:{
            required:$('#this_field_required').val()}
        });

        //TODO: Do not hard code AM here, pass custom message in order to support tri lingual
        if ($('#alienationType').val() != 5 && $('#alienationType').val() != 6) {
            $("#name").rules("add", {required:true, messages:{
                required:$('#this_field_required').val()}
            }); //TODO: name of the holder need to be renamed. Dont use term "name"
            $("#nic").rules("add", {NICNo:true, messages:{
                NICNo:$('#pls_enter_valid_nic_no').val()}
            });
            $("#mobile").rules("add", {phoneNo:true, messages:{
                phoneNo:$('#pls_enter_valid_phone_no').val()}
            });
            $("#landPhone").rules("add", {phoneNo:true, messages:{
                phoneNo:$('#pls_enter_valid_phone_no').val()}
            });
            $("#email").rules("add", {email:true, messages:{
                email:$('#pls_enter_valid_email').val()}
            });
            $("#fax").rules("add", {phoneNo:true, messages:{
                phoneNo:$('#pls_enter_valid_fax_no').val()}
            });
            $("#dateOfBirth").rules("add", {isDateFormated:true,ageValidate:true, messages:{
                ageValidate:$('#pls_enter_valid_age').val()}
            });
            $("#issueDate").rules("add", {isDateFormated:true});
        }
        if ($('#alienationType').val() == 2) {
            $("#minHectareId").rules("add", {number:true, messages:{
                number:$('#pls_enter_valid_no').val()}
            });
            $("#minAcreId").rules("add", {number:true, messages:{
                number:$('#pls_enter_valid_no').val()}
            });
            $("#minRoodsId").rules("add", {number:true, messages:{
                number:$('#pls_enter_valid_no').val()}
            });
            $("#minPerchesId").rules("add", {number:true, messages:{
                number:$('#pls_enter_valid_no').val()}
            });
            $("#minFraction").rules("add", {number:true, messages:{
                number:$('#pls_enter_valid_no').val()}
            });
            $("#mortgagePeriodInYears").rules("add", {digits:true, messages:{
                digits:$('#pls_enter_valid_no').val()}
            });
            $("#mortgagePeriodInMonths").rules("add", {digits:true, messages:{
                digits:$('#pls_enter_valid_no').val()}
            });
            $("#issueDate").rules("add", {isDateFormated:true});
            $("#folioDate").rules("add", {isDateFormated:true});
            $("#startedDate").rules("add", {isDateFormated:true});
        }
        if ($('#alienationType').val() == 3) {
            $("#valuation").rules("add", {positiveNumber:true, messages:{
                positiveNumber:$('#pls_enter_valid_no').val()}
            });
            $("#rental").rules("add", {positiveNumber:true, messages:{
                positiveNumber:$('#pls_enter_valid_no').val()}
            });
            $("#issueDate").rules("add", {isDateFormated:true});
            $("#occupier-dob'+occupierIndex+'").rules("add", {isDateFormated:true});
        }
        if ($('#alienationType').val() == 4) {
            //$("#issueDate").rules("add", "required");
            $("#leasePeriod").rules("add", {required:true,digits:true, messages:{
                required:$('#this_field_required').val(),
                digits:$('#pls_enter_valid_no').val()}
            });
            $("#leasePeriodWord").rules("add", {required:true, messages:{
                required:$('#this_field_required').val()}
            });
            $("#leaseDiagramNo").rules("add", {required:true, messages:{
                required:$('#this_field_required').val()}
            });
            $("#developed-value").rules("add", {positiveNumber:true, messages:{
                positiveNumber:$('#pls_enter_valid_no').val()}
            });
            $("#commercial-value").rules("add", {positiveNumber:true, messages:{
                positiveNumber:$('#pls_enter_valid_no').val()}
            });
            $("#undeveloped-value").rules("add", {positiveNumber:true, messages:{
                positiveNumber:$('#pls_enter_valid_no').val()}
            });
            $("#leaseArrearsFromYear").rules("add", {digits:true, messages:{
                digits:$('#pls_enter_valid_no').val()}
            });
            $("#leaseArrearsToYear").rules("add", {digits:true, messages:{
                digits:$('#pls_enter_valid_no').val()}
            });
            $("#amend-period").rules("add", {digits:true, messages:{
                digits:$('#pls_enter_valid_no').val()}
            });
            $("#mortgagePeriodInYears").rules("add", {digits:true, messages:{
                digits:$('#pls_enter_valid_no').val()}
            });
            $("#mortgagePeriodInMonths").rules("add", {digits:true, messages:{
                digits:$('#pls_enter_valid_no').val()}
            });
            $("#issueDate").rules("add", {isDateFormated:true});
            $("#folioDate").rules("add", {isDateFormated:true});
            $("#startedDate").rules("add", {isDateFormated:true});
        }
        if ($('#alienationType').val() == 7) {
            $("#valuation").rules("add", {positiveNumber:true, messages:{
                positiveNumber:$('#pls_enter_valid_no').val()}
            });
            $("#issueDate").rules("add", {isDateFormated:true});
            $("#folioDate").rules("add", {isDateFormated:true});
            $("#paymentDate").rules("add", {isDateFormated:true});
        }
        if ($('#alienationType').val() == 5) {
            $("#mobile").rules("add", {phoneNo:true, messages:{
                phoneNo:$('#pls_enter_valid_phone_no').val()}
            });
            $("#landPhone").rules("add", {phoneNo:true, messages:{
                phoneNo:$('#pls_enter_valid_phone_no').val()}
            });
            $("#email").rules("add", {email:true, messages:{
                email:$('#pls_enter_valid_email').val()}
            });
            $("#fax").rules("add", {phoneNo:true, messages:{
                phoneNo:$('#pls_enter_valid_fax_no').val()}
            });
            $("#issueDate").rules("add", {isDateFormated:true});
        }
        if ($('#alienationType').val() == 6) {
            $("#issueDate").rules("add", {isDateFormated:true});
            $("#folioDate").rules("add", {isDateFormated:true});
        }
    }
}*/
</script>
<h2><s:label value="%{getText('alienation_info.label')}"/></h2>
<fieldset>
    <table class="width-100">
        <tr id="alienation-type">
            <td><s:label value="%{getText('alienation_method.label')}"/></td>
            <td colspan="3"><s:select list="alienationTypeList" name="alienationType"
                                      id="alienationType"
                                      headerKey="0"
                                      headerValue=""
                                      onchange="loadAlienationData();" cssClass="width-250-px"/>

            </td>
        </tr>
    </table>
    <table class="width-100" id="alienation-details">

    </table>
    <s:hidden name="holder.id"/>


    <table class="width-100" id="commentOnAlienation">

        <tr>
            <td colspan="4">
                <s:label value="%{getText('verified_by_beneficiary.label')}"/>
                <s:radio name="alienation.verifiedByBeneficiary" id="verifiedByBeneficiary"
                         list="#@java.util.HashMap@{'false':getText('no.label'),'true':getText('yes.label')}"/>
            </td>
        </tr>
        <tr>
            <td><s:label value="%{getText('comment_about_alienation.label')}"/></td>
            <td colspan="3"><s:textarea id="alienationComment" name="alienation.alienationComment"
                                        cssClass="width-595-px" rows="1"/></td>
        </tr>
    </table>
    <div id="alienationDocuments">
        <s:if test="!viewMode">

        </s:if>
    </div>
</fieldset>

<s:hidden id="pls_select_alienation_method" value="%{getText('pls_select_alienation_method.label')}"/>
<%--</s:form>--%>
